cmake_minimum_required(VERSION 3.16)

project(QtQuickRO VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


set(QMLPluginDir "${BuildTargetDir}/plugins")

find_package(Qt6 6.2 COMPONENTS Network Quick Quick3D REQUIRED)

fileRecursive(${CMAKE_CURRENT_SOURCE_DIR} "*.cpp" CPP_FILES)
fileRecursive(${CMAKE_CURRENT_SOURCE_DIR} "*.h" HEADER_FILES)

qt_add_library(${PROJECT_NAME} SHARED)
qt_add_qml_module(${PROJECT_NAME}
    URI ${PROJECT_NAME}
    VERSION 1.0
    QML_FILES
    SOURCES
    ${CPP_FILES}
    ${HEADER_FILES}
)

set(TargetOutputDir ${QMLPluginDir}/${PROJECT_NAME})

set_target_properties(${PROJECT_NAME} PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
    RUNTIME_OUTPUT_DIRECTORY ${TargetOutputDir}
)

#编译后拷贝qmldir文件
add_custom_command(
    TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E
    copy
    "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
    "${TargetOutputDir}"
)

#编译后拷贝qml.types文件
add_custom_command(
    TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E
    copy
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.qmltypes"
    "${TargetOutputDir}"
)

target_compile_definitions(${PROJECT_NAME}
    PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME}
    PRIVATE Qt6::CorePrivate Qt6::Quick Qt6::QuickPrivate Qt6::Quick3D Qt6::Network Qt6::CorePrivate)

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

